// pages/regimental-commander/store-cancellation/store-cancellation.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    remark: '',
    loading: false
  },

  /**
   * 输入内容数据双向绑定
   * @param {Object} e 
   */
  updateContent: function(e) {
    const { detail } = e
    this.setData({
      remark: detail
    })
  },
  isDeliverStop(){
    const urlStr = app.getNetAddresss('plugin.package-deliver.frontend.deliver-stop-apply.verify')
    const _this = this
    //this.setData({ loading: true })
    //wx.showLoading({ title: '数据提交中...' })
    app._getNetWork({
      url: urlStr,
      success: function(res) {
        const resData = res.data
        if (resData.result == 0) {
          app.tips(resData.msg)
          setTimeout(()=>{
            wx.navigateBack({
              delta: 1
            });
          },1500)
          
        } 
      },
      complete: function() {
        // wx.hideLoading()
        // _this.setData({ loading: false })
      }
    })
  },
  closeStoreConfirm: function() {
    const { remark, loading } = this.data
    if (loading) return
    const _this = this
    if (remark == '') {
      app.tips('请输入门店关闭原因！')
      return
    }
    wx.showModal({
      title: '提示',
      content: '确认要关闭门店吗！',
      complete: (res) => {
        if (res.confirm) {
          _this.closeStore()
        }
      }
    })
  },

  closeStore: function() {
    const urlStr = app.getNetAddresss('plugin.package-deliver.frontend.deliver-stop-apply.save')
    const _this = this
    const { remark } = this.data
    this.setData({ loading: true })
    wx.showLoading({ title: '数据提交中...' })
    app._getNetWork({
      url: urlStr,
      data: { remark },
      success: function(res) {
        const resData = res.data
        if (resData.result == 1) {
          wx.showModal({
            title: '成功',
            content: '门店关闭申请已提交，请等待审核！',
            showCancel: false,
            complete: (resC) => {
              if (resC.confirm) {
                wx.navigateBack({
                  delta: 1
                });
              }
            }
          })
        } else {
          app.tips(resData.msg || '申请失败！')
        }
      },
      complete: function() {
        wx.hideLoading()
        _this.setData({ loading: false })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.isDeliverStop()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})